Object.prototype.c = 3
let obj = {
    a: 1,
    b: {n: 1}
}

function clone(obj) {
    let newobj = {}
    for (let key in obj){
        if(obj.hasOwnProperty(key)){
            newobj[key] = obj[key]
        }
    }
    return newobj
}


function deepClone(obj) {
    let newObj = {}
    for (let key in obj){
        if(obj.hasOwnProperty(key)){
            if(typeof obj[key] === 'object' && obj[key] !== null){
                newObj[key] = deepClone(obj[key]);
            } else {
            newObj[key] = obj[key]
                    }
    }
}
return newObj
}

let obj2 = clone(obj)
let obj3 = deepClone(obj)
obj.b.n=2
console.log(obj2,obj3);


function deepclone(obj){
    return new Promise(resolve =>{
        const { port1, port2 } = new MessageChannel()
        port1.postMessage(obj)
        port2.onmessage = function (msg) {
            resolve(msg.data); 
    }
    })
    
}

deepclone(obj).then(res=>{
    obj.b.n = 10
    console.log(res); 
})


